package oop.ex3.messages;

import java.io.IOException;

import oop.ex3.sockets.ClientSocket;

public class FileMessage extends SimpleMessage {
	
	public static String[] _headers = {ValidHeaders.CONTAINFILE, 
		ValidHeaders.DONTCONTAINFILE, ValidHeaders.WANTFILE, 
		ValidHeaders.NSCONTAINFILE};

	private String _fileName;
	
	public FileMessage(String msgName, String file) {
		super(msgName);
		_fileName = file;
	}
	
	public FileMessage(String msgName){
		super(msgName);
	}
	
	public String getFileName(){
		return _fileName;
	}
	
	public void sendMessage(ClientSocket socket) throws IOException{
		System.out.println("OUT <to: "+socket.getPort()+"> "+_header);
		socket.writeToSocket(_header);
		socket.writeToSocket(_fileName);
	}
	
	public FileMessage readMessage(ClientSocket socket) throws IOException{
		System.out.println("IN <from: "+socket.getPort()+"> "+_header);
		_fileName = socket.readUTF();
		socket.readUTF();
		return this;
	}
	

}
